<template>
    <div>
        <el-table :data="tableData" style="width: 100%">
            <el-table-column prop="name" label="投递岗位" width="200">
            </el-table-column>
            <el-table-column prop="salary_down" label="接受底薪" width="200">
            </el-table-column>
            <el-table-column prop="salary_up" label="期望薪水" width="200">
            </el-table-column>
            <el-table-column prop="tel" label="联系电话" width="200">
            </el-table-column>
            <el-table-column prop="intro" label="岗位介绍" width="200">
            </el-table-column>
            <el-table-column label="公司" width="150">
                <template slot-scope="scope">
                    <el-button type="primary" size="mini" @click="find1(scope.$index)"
                    >公司详情
                    </el-button
                    >
                </template>
            </el-table-column>
            <el-table-column label="部门" width="150">
                <template slot-scope="scope">
                    <el-button type="warning" size="mini" @click="find2(scope.$index)"
                    >部门详情
                    </el-button
                    >
                </template>
            </el-table-column>
            <el-table-column
                    fixed="right"
                    prop="tag"
                    label="审批状态"
                    width="100"
                    :filters="[{ text: '未通过', value: '未通过' }, { text: '已入职', value: '已入职' }, { text: '已拒绝', value: '已拒绝' },{ text: '待审核', value: '待审核' }, { text: '已通过', value: '已通过' },{ text: '已接受', value: '已接受' }]"
                    :filter-method="filterTag"
                    filter-placement="bottom-end">
                >
                <template slot-scope="scope">

                    <el-tag :type="scope.row.tag == '未通过'? 'danger' : (scope.row.tag == '已入职' ? 'success':(scope.row.tag == '已拒绝' ? 'danger' :(scope.row.tag == '待审核' ? 'primary' :(scope.row.tag == '已通过' ? 'success' : (scope.row.tag == '已接受' ? 'primary' : '')))))"
                            disable-transitions>{{scope.row.tag}}
                    </el-tag>

                </template>
            </el-table-column>

            <el-table-column
                    fixed="right"
                    width="100"
                    label="操作">
                <template slot-scope="scope">
                    <el-button @click="agree(scope.row)" style="padding: 3px" size="mini">接受</el-button>
                    <el-button @click="refuse(scope.row)" style="padding: 3px" size="mini">拒绝</el-button>
                </template>
            </el-table-column>
        </el-table>
    </div>
</template>

<script>
    import axios from "axios";
    import {Message} from "element-ui";

    export default {
        name: "RecMy",
        created() {
            this.getRequest("/rec/my/get").then((data) => {
                //   console.log(data.data);
                if (data) {
                    // console.log(data.data.wanteds);

                    data.data.wanteds.forEach((item) => {

                        // console.log(item);
                        this.tableData.push({
                            wid: item.id,
                            name: item.name,
                            salary_down: item.salaryDown,
                            salary_up: item.salaryUP,
                            tel: item.tel,
                            intro: item.intro,
                            tag: item.status,
                        });
                        this.companys.push(item.company);
                        this.departments.push(item.department);
                        // console.log(item.status);
                    });
                    // console.log(this.companys);
                    // console.log(this.departments);
                }
            });
        },
        data() {
            return {
                tableData: [],
                companys: [],
                departments: [],
            };
        },
        methods: {
            filterTag(value, row) {
                return row.tag === value;
            },
            agree(data) {
                console.log(data);

                if (data.status == "已通过") {

                    let url = '/rec/modify';
                    return axios({
                        method: 'post',
                        url: `${url}`,
                        params: {
                            'uid': window.sessionStorage.getItem("uid"),
                            'wid': data.wid,
                            'status': "已接受",
                        }
                    })

                } else {
                    Message.error({message: '无效操作!'})
                }


            },
            refuse(data) {
                if (data.status == "已通过") {

                    let url = '/rec/modify';
                    return axios({
                        method: 'post',
                        url: `${url}`,
                        params: {
                            'uid': window.sessionStorage.getItem("uid"),
                            'wid': data.wid,
                            'status': "已拒绝",
                        }
                    })

                } else {
                    Message.error({message: '无效操作!'})
                }
            },
            find1(index) {
                // console.log(index);
                this.dialogVisible2 = true;
                // console.log(this.companys);
                // console.log(this.departments[index].intro);
                this.form.name = this.departments[index].name;
                this.form.intro = this.departments[index].intro;
            },
            find2(index) {

                this.rec.uid = JSON.parse(window.sessionStorage.getItem("uid"));
                // console.log(this.tableData);
                this.rec.wid = this.tableData[index].id;
                this.rec.status = "待审核";
                // console.log(this.rec);

                this.axios({
                    url: '/rec/modify',
                    method: 'post',
                    params: {'uid': this.rec.uid, 'wid': this.rec.wid, 'status': this.rec.status},
                })
                    .then((res) => {

                        this.$message.success(res.msg);
                    }).catch((error) => {

                    this.tableData[index].tag = '已申请过该职位';
                    this.tableData[index].con = '已投递';

                    // console.log(this.tableData);
                    this.$message.error("上传失败");
                    //alert("无法展示");

                });

            },
        }
    };
</script>

<style scoped>
</style>